import { EventI } from "@/models/events";
import moment from "moment";

export const EVENT_DATA: Record<
  string,
  { backgroundColor: string; title: string }
> = {
  work_time: {
    backgroundColor: "#0052FF",
    title: "Рабочее время",
  },
  holiday: {
    backgroundColor: "#FF66B2",
    title: "Выходной",
  },
  sick: {
    backgroundColor: "#6666FF",
    title: "Больничный",
  },
  vacation: {
    backgroundColor: "#FF9933",
    title: "Отпуск",
  },
  work_delta: {
    backgroundColor: "#48b12d",
    title: "Предложенное время",
  },
  time_off: {
    backgroundColor: "#FF9933",
    title: "Отгул",
  },
};

export const convertEventTime = (event: EventI, end?: boolean) => {
  return moment(event.date)
    .add(end ? event.end_time : event.start_time)
    .toDate()
    .getTime();
};

export function downloadBlob(blob: Blob, filename: string): void {
  const link = document.createElement("a");
  const url = URL.createObjectURL(blob);
  link.setAttribute("href", url);
  link.setAttribute("download", filename);
  link.style.display = "none";
  document.body.appendChild(link);
  link.click();
  document.body.removeChild(link);
}
